/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool. 

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.
  
*/

#include "events.h"

CBaseEvent::CBaseEvent(eEventType eventType)
{
    mEventType = eventType;
}

CBaseEvent::~CBaseEvent()
{

}

eEventType CBaseEvent::getEventType()
{
    return mEventType;
}

string CBaseEvent::getEventTypeStr()
{
    string ev_type_name;

    switch (mEventType)
    {
    case EV_KEY_PRESS:
        ev_type_name = "KEY PRESSED";
        break;
    case EV_CAMERA_MOVED:
        ev_type_name = "CAMERA MOVED";
        break;
    case EV_CUEBALL_LAUNCHED:
        ev_type_name = "CUE BALL LAUNCHED";
        break;
    case EV_BALL_MOVED:
        ev_type_name = "BALL MOVED";
        break;
    case EV_BALL_COLLISION:
        ev_type_name = "BALL/BALL COLLISION";
        break;
    case EV_TABLE_COLLISION:
        ev_type_name = "BALL/TABLE COLLISION";
        break;
    case EV_BALL_POCKETED:
        ev_type_name = "BALL POCKETED";
        break;
    case EV_BALL_ILLEGALLY_POCKETED:
        ev_type_name = "BALL ILLEGALLY POCKETED";
        break;
    case EV_CUEBALL_POCKETED:
        ev_type_name = "CUE BALL POCKETED";
        break;
    case EV_START_GAME_REQUESTED:
        ev_type_name = "START GAME REQUESTED";
        break;
    case EV_GAME_ENDED:
        ev_type_name = "GAME ENDED";
    case EV_QUIT_APPLICATION:
        ev_type_name = "QUIT GAME";
        break;
    }

    return ev_type_name;
}

CKeyEvent::CKeyEvent(int whichKey) :
    CBaseEvent(EV_KEY_PRESS)
{
    mKey = whichKey;
}

CKeyEvent::~CKeyEvent()
{

}

int CKeyEvent::key()
{
    return mKey;
}

CBallMovedEvent::CBallMovedEvent(eObjectID id, CVector3 pos, CVector3 heading, CVector3 rotAxis, float rotAngle) :
    CBaseEvent(EV_BALL_MOVED)
{
    mBallID = id;
    mNewPosition = pos;
    mNewHeading = heading;
    mNewRotationAxis = rotAxis;
    mNewRotationAngle = rotAngle;
}

CBallMovedEvent::~CBallMovedEvent()
{

}

eObjectID CBallMovedEvent::id()
{
    return mBallID;
}

CVector3 CBallMovedEvent::position()
{
    return mNewPosition;
}

CVector3 CBallMovedEvent::heading()
{
     return mNewHeading;
}

CVector3 CBallMovedEvent::rotationAxis()
{
     return mNewRotationAxis;
}

float CBallMovedEvent::rotationAngle()
{
    return mNewRotationAngle;
}

CCameraMovedEvent::CCameraMovedEvent(CVector3 pos) :
    CBaseEvent(EV_CAMERA_MOVED)
{
    mNewPosition = pos;
}

CCameraMovedEvent::~CCameraMovedEvent()
{

}

CVector3 CCameraMovedEvent::position()
{
    return mNewPosition;
}

CTableCollisionEvent::CTableCollisionEvent(eObjectID id, CVector3 point, CVector3 normal) :
    CBaseEvent(EV_TABLE_COLLISION)
{
    mBallID = id;
    mCollisionPoint = point;
    mCollisionNormal = normal;
}

CTableCollisionEvent::~CTableCollisionEvent()
{

}

eObjectID CTableCollisionEvent::id()
{
    return mBallID;
}

CVector3 CTableCollisionEvent::collisionPoint()
{
    return mCollisionPoint;
}

CVector3 CTableCollisionEvent::collisionNormal()
{
    return mCollisionNormal;
}

CBallCollisionEvent::CBallCollisionEvent(eObjectID id1, eObjectID id2, CVector3 point, CVector3 normal) :
    CBaseEvent(EV_BALL_COLLISION)
{
    mBallID_1 = id1;
    mBallID_2 = id2;
    mCollisionPoint = point;
    mCollisionNormal = normal;
}

CBallCollisionEvent::~CBallCollisionEvent()
{

}

eObjectID CBallCollisionEvent::id1()
{
    return mBallID_1;
}

eObjectID CBallCollisionEvent::id2()
{
    return mBallID_2;
}

CVector3 CBallCollisionEvent::collisionPoint()
{
    return mCollisionPoint;
}

CVector3 CBallCollisionEvent::collisionNormal()
{
    return mCollisionNormal;
}

CCueBallLaunchedEvent::CCueBallLaunchedEvent(CVector3 hitPosition, CVector3 newVelocity) :
    CBaseEvent(EV_CUEBALL_LAUNCHED)
{
    mHitPosition = hitPosition;
    mNewVelocity = newVelocity;
}

CCueBallLaunchedEvent::~CCueBallLaunchedEvent()
{

}

CVector3 CCueBallLaunchedEvent::position()
{
    return mHitPosition;
}

CVector3 CCueBallLaunchedEvent::velocity()
{
    return mNewVelocity;
}

CBallPocketedEvent::CBallPocketedEvent(eObjectID id, CVector3 position, int currentScore, unsigned int ballsRemaining) :
    CBaseEvent(EV_BALL_POCKETED)
{
    mID = id;
    mPosition = position;
    mScore = currentScore;
    mBallsLeft = ballsRemaining;
}

CBallPocketedEvent::~CBallPocketedEvent()
{

}

CVector3 CBallPocketedEvent::position()
{
    return mPosition;
}

eObjectID CBallPocketedEvent::id()
{
    return mID;
}

int CBallPocketedEvent::score()
{
    return mScore;
}

int CBallPocketedEvent::ballsLeft()
{
    return mBallsLeft;
}

CCueBallPocketedEvent::CCueBallPocketedEvent(CVector3 initPosition, int currentScore, unsigned int ballsRemaining) :
    CBaseEvent(EV_CUEBALL_POCKETED)
{
    mInitialPosition = initPosition;
    mScore = currentScore;
    mBallsLeft = ballsRemaining;
}

CCueBallPocketedEvent::~CCueBallPocketedEvent()
{

}

CVector3 CCueBallPocketedEvent::position()
{
    return mInitialPosition;
}

int CCueBallPocketedEvent::score()
{
    return mScore;
}

int CCueBallPocketedEvent::ballsLeft()
{
    return mBallsLeft;
}

CGameEndedEvent::CGameEndedEvent(bool won) :
    CBaseEvent(EV_GAME_ENDED)
{
    mGameIsWon = won;
}

CGameEndedEvent::~CGameEndedEvent()
{

}

bool CGameEndedEvent::gameIsWon()
{
    return mGameIsWon;
}
